<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
    <style type="text/css">
        .serachkind{
          width: 5.6%!important;
        }
        .searchcontent{
            width: 6.5%!important;
        }
        .layui-form-label{
            text-align: left;
        }
        .layui-form-label{
            padding: 9px 0;
        }
    </style>
</head>
<body class="layui-layout-body">


<blockquote class="layui-elem-quote">
    <div class=" layui-form">
        <div class="layui-form-item">


            <div class="layui-input-inline serachkind">
                <select name="" lay-verify="required" id="khSearchKind" lay-filter="khSearchKind">
                    <option value="">客户搜索</option>
                    <option value="khjc">客户简称</option>
                    <option value="khzjm">助记码</option>
                </select>

                <select lay-filter="dingdan" id="ddSearchKind" lay-filter="ddSearchKind">
                    <option value="">订单搜索</option>
                    <option value="ddzt">订单状态</option>
                    <option value="ddh">订单号</option>
                    <option value="ddlx">订单类型</option>
                </select>
            </div>
            <div class="layui-input-inline searchcontent" id = "searchContentCon">
                <select class="layui-input" id="khSearchContent" lay-search>
                    <option value="">请选择</option>
                </select>
                <div id = "ddSearchContentCon">
                    <select class="layui-input" id="ddSearchContent" lay-search>
                        <option value="">请选择</option>
                    </select>
                </div>
                <!--<div id="ddh" style="display: none" ><select   class="layui-input"  id="ddhSearchContent" lay-search><option value="">请选择</option></select></div>-->
                <!--<div id="ddzt"  >-->
                <!--<select name=""   id="ddSearchContent">-->
                <!--<option value=""></option>-->
                <!--<option value="待发布">待发布</option>-->
                <!--<option value="已发布">已发布</option>-->
                <!--<option value="已完成">已完成</option>-->
                <!--</select>-->
                <!--</div>-->
            </div>


            <div class="layui-input-inline serachkind" >
                <select name="city" id="xlSearchKind" lay-filter="xlSearchKind">
                    <option value="">线路搜索</option>
                    <option value="xlmc">线路名称</option>
                    <option value="xlzjm">助记码</option>
                </select>
                <select name="city" lay-verify="required" id="qySearchKind" lay-filter="qySearchKind">
                    <option value="">区域搜索</option>
                    <option value="qymc">区域名称</option>
                    <option value="qyzjm">助记码</option>
                </select>
            </div>

            <div class="layui-input-inline searchcontent">
                <select type="text" class="layui-input" id="xlSearchContent" lay-search>
                    <option value="">请选择</option>
                </select>
                <select type="text" class="layui-input" id="qySearchContent" lay-search>
                    <option value="">请选择</option>
                </select>
            </div>

            <div class="layui-input-inline" style="width: 7.5%;margin-right: 0">
                <label class="layui-form-label" style="width: 100%;">订单起始日期</label>
                <label class="layui-form-label" style="width: 100%;">订单结束日期</label>
            </div>
            <div class="layui-input-inline" style="width: 5.5%">
                <input type="text" class="layui-input" id="searchQsrqContent">
                <input type="text" class="layui-input" id="searchJsrqContent">
            </div>
            <div class="layui-input-inline" style="width: 5%">
                <label class="layui-form-label">星期</label>
                <label class="layui-form-label">订单日期</label>
            </div>
            <div class="layui-input-inline" style="width: 100px">
                <select class="layui-form-label" id="xingqi">
                    <option value=""></option>
                    <option value="Monday">星期一</option>
                    <option value="Tuesday">星期二</option>
                    <option value="Wednesday">星期三</option>
                    <option value="Tuesday">星期四</option>
                    <option value="Friday">星期五</option>
                    <option value="Saturday">星期六</option>
                    <option value="Sunday">星期日</option>
                </select>

                <input type="text" class="layui-input" id="ddrq">
            </div>

            <div class="layui-input-inline" style="width: 80px">
                <button class="layui-btn layui-btn-normal" id="search" style="margin-bottom: 5%">搜索</button>
                <button class="layui-btn layui-btn-normal" id="newOrder"> 生成订单</button>

            </div>


            <div class="layui-input-inline " style=" width:10%; margin-left: 2%">
                <button type="button" class="layui-btn layui-btn-normal" id="alldel" style="margin-bottom: 5%">批量删除</button>
                <button type="button" class="layui-btn layui-btn-normal" id="allpost">批量发布</button>

            </div>


            <div class="layui-input-inline " style=" width:10%; margin-left: 2%">
                <button type="button" class="layui-btn layui-btn-normal" id="all" style="margin-bottom: 5%">
                    &nbsp&nbsp&nbsp&nbsp重置&nbsp&nbsp&nbsp
                </button>
                <button type="button" class="layui-btn layui-btn-normal" id="newOtherOrder">新增零散订单</button>

            </div>

        </div>
    </div>
</blockquote>
<div class="layui-row">
    <div class="layui-col-xs12">
        <script type="text/html" id="opera">

            {{#  if(d.ddzt != '待发布'){ }}
            {{# if(getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="detail">查看
            </button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="addcar">加车
            </button>
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled lay-event="delete">删除
            </button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="post">发布
            </button>

            {{# }else{ }}
            {{# if(getQueryVariable("AC") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="addcar">加车
            </button>
            {{# if(getQueryVariable("PD") == "true"){ }}
            <button class="layui-btn  layui-btn-xs layui-btn-danger" lay-event="delete">删除</button>
            {{# }else{ }}
            <button class="layui-btn  layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="delete">删除
            </button>
            {{# } }}
            <button class="layui-btn  layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="post">发布</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="addcar">加车</button>
            {{# if(getQueryVariable("PD") == "true"){ }}
            <button class="layui-btn  layui-btn-xs layui-btn-danger" lay-event="delete">删除</button>
            {{# }else{ }}
            <button class="layui-btn  layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="delete">删除
            </button>
            {{# } }}
            <button class="layui-btn  layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="post">发布</button>
            {{# } }}


            {{# } }}
            {{# } else { }}

            {{# if(getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="detail">查看
            </button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="addcar">加车
            </button>
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled lay-event="delete">删除
            </button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="post">发布
            </button>

            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  " lay-event="detail">查看</button>

            {{#  if(getQueryVariable("AC") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="addcar">加车
            </button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  " lay-event="addcar">加车</button>
            {{# } }}
            {{#  if(getQueryVariable("D") == "false"){ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled lay-event="delete">删除
            </button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs  " lay-event="delete">删除</button>
            {{# } }}

            {{#  if(getQueryVariable("PO") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled lay-event="post">发布
            </button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  " lay-event="post">发布</button>
            {{# } }}


            {{# } }}

            {{#  } }}


        </script>

        <table id="table" lay-filter="Table"></table>
        <div id="laypage"></div>
    </div>
</div>


<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/autocomplete.js"></script>
<script src="../js/tools.js"></script>

<script>

    //JavaScript代码区域
    layui.use(['form', 'table', 'jquery', 'layer', 'element', 'laydate','laypage'], function () {
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;
        var element = layui.element;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var tableheight = 'full-200';
        var tablewidth = 75;
        var currentPage = 1;
        var limitcount = 10;
        var curnum = 1;
        var laypage = layui.laypage;
        var tablehead = [[ //表头
            {type: 'checkbox'},
            {type: 'numbers', title: '序号', align: 'center'}
            , {field: 'ddh', title: '订单号', align: 'center', width: 150}
            , {field: 'ddzt', title: '订单状态', align: 'center', width: 100}
            , {field: 'ddrq', title: '订单日期', align: 'center', width: 120}
            , {field: 'ddlx', title: '订单类型', align: 'center', width: 100}
            , {field: 'khjc', title: '客户简称', align: 'center', width: 100}
            , {field: 'qymc', title: '区域名称', align: 'center', width: 100}
            , {field: 'xlmc', title: '线路名称', align: 'center', width: 220}
            , {field: 'huowu', title: '货物', align: 'center', width: 100}
            , {field: 'yunfei', title: '运费', align: 'center', width: 100}
            , {title: '操作', align: 'center', templet: '#opera'}
        ]]



//获取url参数 渲染 权限控制的页面
        if (getQueryVariable("OORDER") == "false") {
            $("#newOtherOrder").attr("disabled", true);
            $("#newOtherOrder").addClass("layui-btn-disabled");
        }
        if (getQueryVariable("ORDER") == "false") {
            $("#newOrder").attr("disabled", true);
            $("#newOrder").addClass("layui-btn-disabled");
        }
        if (getQueryVariable("D") == "false") {
            $("#alldel").attr("disabled", true);
            $("#alldel").addClass("layui-btn-disabled");
        }
        if (getQueryVariable("PO") == "false") {
            $("#allpost").attr("disabled", true);
            $("#allpost").addClass("layui-btn-disabled");
        }
        //搜索的订单状态还是订单号
        form.on('select(dingdan)', function (data) {
            if (data.value == "ddh") {
                $("#ddSearchContent").empty();
                $("#ddSearchContentCon").remove();
                $("#searchContentCon").append("<div id='ddSearchContentCon'><input id=\"ddSearchContent\" class=\"ym-qatitle layui-input \" placeholder=\"模糊匹配\" autocomplete=\"off\"/></div> ");
                $.ajax({
                    url: contextPath + "/order",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        var countriesArray =[]
                        console.log(res.list)
                        for(var i in res.list){

                            countriesArray.push({data:i,value:res.list[i].ddh})

                        }
                        $('#ddSearchContent').autocomplete({
                            lookup: countriesArray
                        });
                   /*     for (var i in res.list) {
                            var option = "<option value='" + res.list[i].ddh + "'>" + res.list[i].ddh + "</option>";
                            $("#ddSearchContent").append(option);
                        }
                        ;
                        form.render('select');*/
                    }
                });
            } else if (data.value == "ddzt") {

                $("#ddSearchContent").empty();
                $("#ddSearchContentCon").remove();
                $("#searchContentCon").append(" <div id=\"ddSearchContentCon\">\n" +
                    "                    <select class=\"layui-input\" id=\"ddSearchContent\" lay-search> <option value=\"\">请选择</option></select>\n" +
                    "                </div>");
                var option1 = "<option value='已发布'>已发布</option>";
                var option2 = "<option value='待发布'>待发布</option>";
                var option3 = "<option value='已完成'>已完成</option>";
                $("#ddSearchContent").append(option1);
                $("#ddSearchContent").append(option2);
                $("#ddSearchContent").append(option3);
                form.render('select');
            } else if (data.value == "ddlx") {
                $("#ddSearchContent").empty();
                $("#ddSearchContentCon").remove();
                $("#searchContentCon").append(" <div id=\"ddSearchContentCon\">\n" +
                    "                    <select class=\"layui-input\" id=\"ddSearchContent\" lay-search> <option value=\"\">请选择</option></select>\n" +
                    "                </div>");
                var option1 = "<option value='批量订单'>批量订单</option>";
                var option2 = "<option value='加车单'>加车单</option>";
                var option3 = "<option value='零散订单'>零散订单</option>";
                $("#ddSearchContent").append(option1);
                $("#ddSearchContent").append(option2);
                $("#ddSearchContent").append(option3);
                form.render('select');
            }
        });


        //执行一个laydate实例
        laydate.render({
            elem: '#ddrq' //指定元素
            , theme: '#0099FF'
            , format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#searchQsrqContent' //指定元素
            , theme: '#0099FF'
            , format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#searchJsrqContent' //指定元素
            , theme: '#0099FF'
            , format: 'yyyy-MM-dd'
        });

        //零散订单
        $("#newOtherOrder").on("click", function () {
            layer.open({
                cancel: function (index, layero) {
                    var faIndex = index;
                    layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title: '提示'}, function (index) {
                        //do something
                        layer.close(index);
                        layer.close(faIndex);
                    });
                    return false
                },
                type: 2,
                title: '新建零散订单',
                maxmin: true,
                //点击遮罩关闭层
                area: ['80%', '50%'],
                content: ['./newOtherOrder.html', 'no'],

                end: function () {
                    ordersearch(curnum, limitcount);
                }
            });

        });
        //生成订单
        $("#newOrder").on("click", function () {
            // console.log($("#ddrq").val());
            if ($("#ddrq").val() == "") {
                layer.msg("请选择生成订单日期！");

            } else {
                $(this).attr("disabled", "disabled");
                $.ajax({
                    url: contextPath + "/order/" + $("#ddrq").val(),
                    type: "POST",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        layer.msg(res.message);
                        ordersearch(curnum, limitcount);
                        $("#newOrder").removeAttr("disabled", "disabled");
                    }
                });
            }
        })
//
        //  渲染搜索 select
        form.on("select(khSearchKind)", function (data) {
            if (data.value == "khjc") {
                $("#khSearchContent").empty();
                $.ajax({
                    url: contextPath + "/cstmrlist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#khSearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].khjc + "'>" + res.list[i].khjc + "</option>";
                            $("#khSearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else if (data.value == "khzjm") {
                $("#khSearchContent").empty();
                $.ajax({
                    url: contextPath + "/cstmrlist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#khSearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].xlzjm + "'>" + res.list[i].xlzjm + "</option>";
                            $("#khSearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else {
                $("#khSearchContent").empty();
            }

        });

        form.on("select(xlSearchKind)", function (data) {
            if (data.value == "xlmc") {
                $("#xlSearchContent").empty();
                $.ajax({
                    url: contextPath + "/order/road",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#xlSearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i] + "'>" + res.list[i] + "</option>";
                            $("#xlSearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else if (data.value == "xlzjm") {
                $("#xlSearchContent").empty();
                $.ajax({
                    url: contextPath + "/roadlist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#xlSearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].xlzjm + "'>" + res.list[i].xlzjm + "</option>";
                            $("#xlSearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else {
                $("#xlSearchContent").empty();
            }

        });

        form.on("select(khSearchKind)", function (data) {
            if (data.value == "khjc") {
                $("#khSearchContent").empty();
                $.ajax({
                    url: contextPath + "/cstmrlist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#khSearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].khjc + "'>" + res.list[i].khjc + "</option>";
                            $("#khSearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else if (data.value == "khzjm") {
                $("#khSearchContent").empty();
                $.ajax({
                    url: contextPath + "/cstmrlist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#khSearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].khzjm + "'>" + res.list[i].khzjm + "</option>";
                            $("#khSearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else {
                $("#khSearchContent").empty();
            }

        });

        form.on("select(qySearchKind)", function (data) {
            if (data.value == "qymc") {
                $("#qySearchContent").empty();
                $.ajax({
                    url: contextPath + "/arealist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#qySearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].qymc + "'>" + res.list[i].qymc + "</option>";
                            $("#qySearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else if (data.value == "qyzjm") {
                $("#qySearchContent").empty();
                $.ajax({
                    url: contextPath + "/arealist",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        $("#qySearchContent").append("<option value=''>请选择</option>");
                        for (var i in res.list) {
                            var option = "<option value='" + res.list[i].zjm + "'>" + res.list[i].zjm + "</option>";
                            $("#qySearchContent").append(option);
                        }
                        ;
                        form.render('select');
                    }
                });
            } else {
                $("#qySearchContent").empty();
            }

        });
        //渲染table
        ordermana(curnum, limitcount)
        function ordermana(start,limitsize) {
            layui.use(['table','laypage','laydate'], function(){
                var table = layui.table,
                    laypage = layui.laypage;
                table.render({
                    url: contextPath + "order?pageNum="+start+"&pageSize="+limitsize,
                    elem: '#table',
                    height: tableheight,
                    page: false,
                    id: 'table',
                    cellMinWidth: tablewidth,
                    cols: tablehead,
                    done: function (res, curr,count) {
                        disCheck(res, $, form);
                        laypage.render({
                            elem: 'laypage'
                            , count: count
                            , curr: curnum
                            , limit: limitcount
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    limitcount = obj.limit;
                                    //console.log("curnum"+curnum);
                                    //console.log("limitcount"+limitcount);
                                    //layer.msg(curnum+"-"+limitcount);
                                    ordermana(curnum, limitcount);
                                }
                            }
                        });
                    }
                });
            });
        }

        function ordersearch(start,limitsize) {
            layui.use(['table','laypage','laydate'], function(){
                var table = layui.table,
                    laypage = layui.laypage;
                table.render({
                    url: contextPath + "order?pageNum="+start+"&pageSize="+limitsize+"&"+ $("#khSearchKind").val() + "=" + $("#khSearchContent").val() + "&" + $("#xlSearchKind").val() + "=" + $("#xlSearchContent").val() + "&" + $("#qySearchKind").val() + "=" + $("#qySearchContent").val() + "&" + $("#ddSearchKind").val() + "=" + $("#ddSearchContent").val() + "&qsrq=" + $("#searchQsrqContent").val() + "&" + "jsrq=" + $("#searchJsrqContent").val() + "&xq=" + $("#xingqi").val(),
                    dataType: "object",
                    elem: '#table',
                    height: tableheight,
                    page: false,
                    id: 'table',
                    cellMinWidth: tablewidth,
                    cols: tablehead,
                    done: function (res, curr,count) {
                        disCheck(res, $, form);
                        laypage.render({
                            elem: 'laypage'
                            , count: count
                            , curr: start
                            , limit: limitsize
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    limitcount = obj.limit;
                                    //console.log("curnum"+curnum);
                                    //console.log("limitcount"+limitcount);
                                    //layer.msg(curnum+"-"+limitcount);
                                    ordersearch(curnum, limitcount);
                                }
                            }
                        });
                    }
                });
            });
        }
        //table实例
        $("#all").on('click', function () {
            // curnum =1;
            // ordermana(curnum, limitcount)
            $("#khSearchKind").val("");
            $("#khSearchContent").empty();
            $("#khSearchContent").append("<option value=''>请选择</option>");
            $("#xlSearchKind").val("");
            $("#xlSearchContent").empty();
            $("#xlSearchContent").append("<option value=''>请选择</option>");
            $("#ddSearchKind").val("");
            $("#ddSearchContent").empty();
            $("#ddSearchContentCon").remove();
            $("#searchContentCon").append(" <div id=\"ddSearchContentCon\">\n" +
                "                    <select class=\"layui-input\" id=\"ddSearchContent\" lay-search> <option value=\"\">请选择</option></select>\n" +
                "                </div>");
            $("#qySearchKind").val("");
            $("#qySearchContent").empty();
            $("#qySearchContent").append("<option value=''>请选择</option>");
            $("#searchQsrqContent").val("")
            $("#searchJsrqContent").val("")
            $("#xingqi").val("");
            $("#ddrq").val("");
            form.render('select');
        });
        var url = contextPath + "/order?" + $("#khSearchKind").val() + "=" + $("#khSearchContent").val() + "&" + $("#xlSearchKind").val() + "=" + $("#xlSearchContent").val() + "&" + $("#qySearchKind").val() + "=" + $("#qySearchContent").val() + "&" + $("#ddSearchKind").val() + "=" + $("#ddSearchContent").val() + "&qsrq=" + $("#searchQsrqContent").val() + "&" + "jsrq=" + $("#searchJsrqContent").val() + "&xq=" + $("#xingqi").val();



//监听表格
        table.on('tool(Table)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                layer.open({
                    cancel: function (index, layero) {
                        var body = layer.getChildFrame('body', index);
                        var faIndex = index;
                        // console.log(layero);
                        if (!(body.contents().find("#modiSub").hasClass("layui-btn-disabled"))) {

                            layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title: '提示'}, function (index) {
                                //do something
                                layer.close(index);
                                layer.close(faIndex);
                            });
                        } else {
                            layer.close(faIndex);
                        }

                        return false
                    },
                    type: 2,
                    title: '查看订单信息',
                    maxmin: true,
                    //点击遮罩关闭层
                    area: ['80%', '40%'],
                    content: ['./lookOrder.html', 'no'],
                    success: function (layero, index) {
                        // console.log(data);
                        data.isU = getQueryVariable('U');
                        var body = layer.getChildFrame('body', index);

                        for (var i in data) {
                            body.contents().find("[name='" + i + "']").val(eval("data." + i));
                        }
                    },
                    end: function () {
                        ordersearch(curnum, limitcount);
                    }
                });
            } else if (layEvent === 'delete') {
                layer.confirm('确定删除？', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        url: contextPath + "/order/" + data.ddid,
                        type: "DELETE",
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (res) {
                            layer.msg(res.message);
                            ordersearch(curnum, limitcount);
                        }
                    });
                });
            } else if (layEvent === 'post') {
                $(this).attr("disabled", "disabled");
                $.ajax({
                    url: contextPath + "/order/" + data.ddid,
                    type: "PUT",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (res) {
                        layer.msg(res.message);
                        ordersearch(curnum, limitcount);
                    }
                });

            } else if (layEvent === 'addcar') {

                layer.open({
                    cancel: function (index, layero) {
                        var faIndex = index;
                        layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title: '提示'}, function (index) {
                            //do something
                            layer.close(index);
                            layer.close(faIndex);
                        });
                        return false
                    },
                    type: 2,
                    title: '加车',
                    maxmin: true,
                    //点击遮罩关闭层
                    area: ['80%', '60%'],
                    content: ['./addCar.html', 'no'],
                    success: function (layero, index) {
                        // console.log(data);
                        var body = layer.getChildFrame('body', index);
                        data.ddzt = "待发布";
                        for (var i in data) {
                            body.contents().find("[name='" + i + "']").val(eval("data." + i));
                        }
                    },
                    end: function () {
                        ordersearch(curnum, limitcount);
                    }
                });

            }
        });
//批量操作
        $("#alldel").on('click', function () {
            layer.alert('确认批量删除？', {
                skin: 'layui-layer-lan' //样式类名  自定义样式
                , closeBtn: 1    // 是否显示关闭按钮
                , anim: 1 //动画类型
                , btn: ['确认', '取消'] //按钮
                , icon: 0    // icon
                , yes: function () {
                    $(this).attr("disabled", "disabled");
                    var checkStatus = table.checkStatus('table');
                    var data = {};
                    var ddidList = new Array();
                    for (var k in checkStatus.data) {
                        ddidList.push(checkStatus.data[k].ddid)
                    }
                    data.ddidList = ddidList;
                    console.log(data)
                    $.ajax({
                        url: contextPath + "/order/batch",
                        type: "DELETE",
                        contentType: "application/json;charset=utf-8",
                        data: JSON.stringify(data),
                        dataType: "json",
                        success: function (res) {
                            layer.msg("批量删除" + ddidList.length + "条记录" + res.message);
                            ordersearch(curnum, limitcount);
                            $("#alldel").removeAttr("disabled", "disabled");
                        }
                    });
                }
                , btn2: function () {
                }
            });


        });

        $("#allpost").on('click', function () {
            // layer.alert('确认批量发布？', {
            //     skin: 'layui-layer-lan' //样式类名  自定义样式
            //     ,closeBtn: 1    // 是否显示关闭按钮
            //     ,anim: 1 //动画类型
            //     ,btn: ['确认','取消'] //按钮
            //     ,icon: 0    // icon
            //     ,yes:function(){
            $(this).attr("disabled", "disabled");
            var checkStatus = table.checkStatus('table');
            var data = {};
            var ddidList = new Array();
            for (var k in checkStatus.data) {
                ddidList.push(checkStatus.data[k].ddid)
            }
            data.ddidList = ddidList;
            console.log(data)

            $.ajax({
                url: contextPath + "/order/batch/",
                data: JSON.stringify(data),
                type: "PUT",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (res) {
                    layer.msg("批量发布" + ddidList.length + "条记录" + res.message);
                    console.log(res.message)
                    ordersearch(curnum, limitcount);
                    $("#allpost").removeAttr("disabled", "disabled");
                }
            });
            // }
            // ,btn2:function(){
            // }});


        });
        // table.on('checkbox(Table)',function (obj) {
        //
        //
        // })
//搜索

        $("#search").on('click', function () {
            if ($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() != "") {
                if (!checkEndTime($("#searchQsrqContent").val(), $("#searchJsrqContent").val())) {
                    layer.msg("起始日期大于结束日期!");
                } else {
                    curnum =1;
                    layui.use(['table','laypage','laydate'], function(){
                        var table = layui.table,
                            laypage = layui.laypage;
                        table.render({
                            url: contextPath + "order?pageNum="+curnum+"&pageSize="+limitcount+"&"+ $("#khSearchKind").val() + "=" + $("#khSearchContent").val() + "&" + $("#xlSearchKind").val() + "=" + $("#xlSearchContent").val() + "&" + $("#qySearchKind").val() + "=" + $("#qySearchContent").val() + "&" + $("#ddSearchKind").val() + "=" + $("#ddSearchContent").val() + "&qsrq=" + $("#searchQsrqContent").val() + "&" + "jsrq=" + $("#searchJsrqContent").val() + "&xq=" + $("#xingqi").val(),
                            dataType: "object",
                            elem: '#table',
                            height: tableheight,
                            page: false,
                            id: 'table',
                            cellMinWidth: tablewidth,
                            cols: tablehead,
                            done: function (res, curr,count) {
                                disCheck(res, $, form);
                                laypage.render({
                                    elem: 'laypage'
                                    , count: count
                                    , curr: curnum
                                    , limit: limitcount
                                    , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                                    , jump: function (obj, first) {
                                        if (!first) {
                                            curnum = obj.curr;
                                            limitcount = obj.limit;
                                            //console.log("curnum"+curnum);
                                            //console.log("limitcount"+limitcount);
                                            //layer.msg(curnum+"-"+limitcount);
                                            ordersearch(curnum, limitcount);
                                        }
                                    }
                                });
                            }
                        });
                    });
                }
            } else if ($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() == "") {
                layer.msg("结束日期不能为空！");
            } else if ($("#searchQsrqContent").val() == "" && $("#searchJsrqContent").val() != "") {
                layer.msg("起始日期不能为空！");
            } else {

                curnum =1;
                layui.use(['table','laypage','laydate'], function(){
                    var table = layui.table,
                        laypage = layui.laypage;
                    table.render({
                        url: contextPath + "order?pageNum="+curnum+"&pageSize="+limitcount+"&"+ $("#khSearchKind").val() + "=" + $("#khSearchContent").val() + "&" + $("#xlSearchKind").val() + "=" + $("#xlSearchContent").val() + "&" + $("#qySearchKind").val() + "=" + $("#qySearchContent").val() + "&" + $("#ddSearchKind").val() + "=" + $("#ddSearchContent").val() + "&qsrq=" + $("#searchQsrqContent").val() + "&" + "jsrq=" + $("#searchJsrqContent").val() + "&xq=" + $("#xingqi").val(),
                        dataType: "object",
                        elem: '#table',
                        height: tableheight,
                        page: false,
                        id: 'table',
                        cellMinWidth: tablewidth,
                        cols: tablehead,
                        done: function (res, curr,count) {
                            disCheck(res, $, form);
                            laypage.render({
                                elem: 'laypage'
                                , count: count
                                , curr: curnum
                                , limit: limitcount
                                , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                                , jump: function (obj, first) {
                                    if (!first) {
                                        curnum = obj.curr;
                                        limitcount = obj.limit;
                                        //console.log("curnum"+curnum);
                                        //console.log("limitcount"+limitcount);
                                        //layer.msg(curnum+"-"+limitcount);
                                        ordersearch(curnum, limitcount);
                                    }
                                }
                            });
                        }
                    });
                });
            }
        });


    });

    function disCheck(res, $, form) {
        var data = res.data;
        var allck = true;
        console.log(data)
        for (var item in data) {

            if (data[item].ddzt == "已发布" || data[item].ddzt == "已完成") {//关键点如果data中score包含57那么就不能全选
                allck = false;
                break;
            } else {
                allck = true;
            }

        }

        if (!allck) {

            // console.log(allck)
            $(".layui-table-header").find("input[name = 'layTableCheckbox'][lay-filter='layTableAllChoose']").each(function () {
                $(this).attr("disabled", 'disabled').next().removeClass("layui-form-checked");
                // console.log(this);
                form.render('checkbox');
            });
        } else {
            $(".layui-table-header").find("input[name = 'layTableCheckbox'][lay-filter='layTableAllChoose']").each(function () {
                $(this).removeAttr("disabled", 'disabled').next().removeClass("layui-form-checked");
                // console.log(this);
                form.render('checkbox');
            });
        }
        var i = 0;
        $(".layui-table-body.layui-table-main").find("input[name='layTableCheckbox']").each(function () {
            if (res.data[i].ddzt == "已完成" || res.data[i].ddzt == "已发布") {//关键点如果当前行数据中score包含57那么就不可选
                $(this).attr("disabled", 'disabled').removeAttr("checked");
                form.render('checkbox');
            }
            i++;
        });
        i = 0;
        $(".layui-table-fixed.layui-table-fixed-l").find(".layui-table-body").find("input[name='layTableCheckbox']").each(function () {
            if (res.data[i].ddzt == "已完成" || res.data[i].ddzt == "已发布") {//关键点如果当前行数据中score包含57那么就不可选
                $(this).attr("disabled", 'disabled').removeAttr("checked");
                form.render('checkbox');
            }
            i++;
        });
    }


</script>
</body>
</html>